package com.exam;

public class Beer {
    public static void main(String[] args) {
        System.out.println(buyBear(10, 0, 0));
    }
    public static int buyBear(int money, int cover, int bottle){
        int moneynums = 0, covernums = 0, bottlenums = 0;
        if(money >= 2 || cover >= 4 || bottle >= 2){
            if(money >= 2){
                moneynums = money / 2;
                money %= 2;
            }
            if(cover >= 4){
                covernums = cover / 4;
                cover %= 4;
            }
            if(bottle >= 2){
                bottlenums = bottle / 2;
                bottle %= 2;
            }
        }
        else{
            return 0;
        }
        int sum = moneynums + covernums + bottlenums;
        cover += sum;
        bottle += sum;
        if(sum == 0){
            return 0;
        }
        return  sum + buyBear(money, cover, bottle);
    }
}
